<?php
	session_start();
        include_once(dirname(__FILE__). "/../../core/managers/business/class.user.php");
	include_once(dirname(__FILE__). "/../../core/presenters/administration/orderAdministration/class.orderAdministration_Presenter.php");

        $user = unserialize($_SESSION["current_user"]);

        if((!isset($user) || $user == "")|| $user->getAdmin() == 0){
            //header('index.php');
            echo "<script language='JavaScript'> window.location = '../../home.php'; </script>";
        }
        $pres = new OrderAdministration_Presenter($user->getId());
        $_SESSION['ord_adm_pres'] = serialize($pres);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
	<head>
  		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  		<link rel="stylesheet" media="screen" href="../../generic/generic.css" />
  		<link rel="stylesheet" media="screen" href="admin_order.css" />
		<link rel="icon" type="image/png" href="../../content/images/favicon.ico" />
		
		<!--JQUERY-->
		<script language='JavaScript' src='../../scripts/jquery-ui-1.8.6.custom/js/jquery-1.4.4.min.js'></script>
		<script language='JavaScript' src='../../scripts/jquery-ui-1.8.6.custom/js/jquery-ui-1.8.6.custom.min.js'></script>
		<link rel="stylesheet" media="screen" type="text/css" title="style" href="../../scripts/jquery-ui-1.8.6.custom/css/ui-darkness/jquery-ui-1.8.6.custom.css" />	
		
		<!--Autres scripts-->
		<script language='JavaScript' src='../../scripts/generic.js'></script>
		<script language='JavaScript' src='../../scripts/menu_manager.js'></script>
		<script language='JavaScript' src='admin_order.js'></script>
  		<title>
			Identificator - Administration des ordres
		</title>
	</head>
	<body onload="Hour();">
                <img id="image_fond" src="../../content/images/background/fond.png" style="width:99%; height:99%;"/>
		<?php
			include_once(dirname(__FILE__). "/../../generic/top_level2.php");
			
                        $user_picture_dir = "../../".$pres->getUserPictureDirectory();
                        
			if($user->getPhotoProfil() != ""){
                            echo "<input type='hidden' id='photo_profil' value='".$user_picture_dir.$user->getPhotoProfil()."' />";
                        }
                        else echo "<input type='hidden' id='photo_profil' value='../../content/images/Default_white.png' />";
		?>
		<script language='JavaScript'>
			InitHeader(document.getElementById('photo_profil').value, "Administration des ordres ...", '... voici la liste des ordres', true);
		</script>
		 <div id="content">
			<div id="menu" class="menu">
				<img id="menuImg1" class="menuImg" src="../../content/images/menus/fleche_menu.png" onmouseover="javascript:itemMenuOver(this)" 
                                                                                                                    onmouseout="javascript:itemMenuOver(this)" 
                                                                                                                    style="cursor:pointer;"
                                                                                                                    onclick="javascript:window.location='../../menu.php'"/>
			
				<img id="menuImg2" class="menuImg" src="../../content/images/menus/fleche_admin.png" onmouseover="javascript:itemMenuOver(this)" 
                                                                                                                        onmouseout="javascript:itemMenuOver(this)" 
                                                                                                                        style="cursor:pointer;"
                                                                                                                        onclick="javascript:window.location='../administration.php'"/>
			
				<img id="menuImg2" class="menuImg" src="../../content/images/menus/fleche_ordres.png" onmouseover="javascript:itemMenuOver(this)" 
                                                                                                                        onmouseout="javascript:itemMenuOver(this)" 
                                                                                                                        style="cursor:pointer;"
                                                                                                                        onclick="javascript:window.location='admin_order.php'"/>
			</div>
			<div id="div_middle" class="div_middle">
				<span id='label_Info' class='label_Info'>
                                    
				</span>
                                 <?php
                                    $orderList = $pres->getAllOrder();
                                    foreach($orderList as $order){
                                        echo "<div class='order' id='user_".$order->getId()."'>
                                                    <div class='photo_order'>
                                                        <img src='../../".$pres->getOrderPictureDirectory()."/".$order->getLienImage()."' />
                                                    </div>
                                                    <div class='infos_order'>
                                                        <span>Nom : <input type='text' id='nom_".$order->getId()."' value='".$order->getNom()."' /></span>
                                                        <a href='#modal_".$order->getId()."' name='modal'>
                                                            <img class='man_adm_pic' src='../../content/images/comptes_utilisateurs.png' />   
                                                        </a> 
                                                    </div>
                                                    <div class='traitement_order'>
                                                        <input type='file' name='nom_".$order->getId()."' id='nom_".$order->getId()."' accept='image/*'/>
                                                        <input type='button' id='mod_".$order->getId()."' onclick='update(".$order->getId().")' Value='Modifier' class='bouton bout_sup' /> 
                                                        <input type='button' id='sup_".$order->getId()."' onclick='del(".$order->getId().")' Value='Supprimer' class='bouton bout_mod' />      
                                                    </div>
                                                    
                                              </div>";
                                        //--Gestion de la modale popup
                                        echo "<div class='modal_popup' id='modal_".$order->getId()."'>
                                                Cliquez-glissez de gauche à droite pour les définir les administrateurs de l'ordre : ".$order->getNom()." 
                                            <div id='bloc_gauche'>
                                                <div class='titre_div1'>Personnes</div>
                                                <div id='conteneur_user' class='personnes_gauche droppable_user'>
                                                    ";
                                        $admins = $pres->getAdminToOrder($order->getId());
                                        $users  = $pres->getAllUsers();
                                        
                                        //--Gestion de la liste des utilisateur
                                        foreach($users as $user){
                                            //-Si la liste des admins n'est pas vide
                                            $est_admin = false;
                                            if(count($admins) > 0){
                                                foreach($admins as $admin){
                                                    //--Vérifie que l'utilisateur ne soit pas déja administrateur de cet ordre
                                                    if($admin->getId() == $user->getId()){
                                                        $est_admin = true;
                                                    }
                                                }
                                            }else{
                                                $nonAdmins[] = $user;
                                            }
                                            
                                            if(!$est_admin){
                                                $nonAdmins[] = $user;
                                            }
                                        }
                                        
                                        foreach($nonAdmins as $nonAdmin){
                                            echo "<div class='div_user draggable_user' id='order_".$order->getId()."_nonadmin_".$nonAdmin->getId()."'>
                                                    ".$nonAdmin->getPrenom()." ".$nonAdmin->getNom()."
                                                </div>";
                                        }
                                         
                                        //--Gestion de la liste des administrateur actuels
                                        echo "</div></div>
                                             <div id='bloc_droit'>
                                            <div class='titre_div2'>Administrateurs</div>
                                                <div id='conteneur_admin' class='personnes_droite droppable_admin'>";
                                                if(count($admins) > 0){
                                                    foreach($admins as $admin){
                                                        echo "<div class='div_user draggable_admin' id='order_".$order->getId()."_admin_".$admin->getId()."'>
                                                            ".$admin->getNom()." ";     
                                                        echo "</div>";
                                                    }   
                                                }
                                        echo "</div> 
                                            </div>
                                            </div>";
                                    }
                                ?>
				<span id="label_error" class="label_error"></span>
			</div>
		</div>
		<?php
			include_once(dirname(__FILE__). "/../../generic/footer_level2.php");
		?>
              <div id="mask"></div>
	</body>
</html>
